// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
import store from './store/index'
import '../style/style.css'
import '../src/assets/js/iconfont' //icon库中humi项目
import '../src/font/iconfont'
import '../src/font/fontNew/iconfont' //icon库中1610十防图标项目
import '../src/font/fontNew/iconfont2' // icon库中v6项目
import {renderDisplay} from '../src/untils/scale'
import scroll from 'vue-seamless-scroll'
import publicFunction from '../src/untils/publicFunction'
import config from '../src/config'
import  VueTouch from 'vue-touch' // 左右滑动切换页面
// 大屏幕适配方法
// import "./untils/flexible";
//app兼容低版本安卓
import 'babel-polyfill'
import Es6Promise from 'es6-promise'
require('es6-promise').polyfill()
Es6Promise.polyfill()

import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts

Vue.prototype.publicFunction = publicFunction ;
Vue.use(scroll)
// 左右滑动切换页面
Vue.use(VueTouch,{name:'v-touch'})
VueTouch.config.swipe = {
  threshold:50  //设置左右滑动的距离
}
Vue.use(ElementUI);
Vue.prototype.renderDisplay = renderDisplay
Vue.config.productionTip = false;
Vue.prototype.$http = axios;
// Vue.prototype.$baseUrl= config.url;
Vue.prototype.$http.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';

// Vue.config2.productionTip = false;
 // 判断 生产和开发环境 配置 信息
if(process.env.NODE_ENV === 'development'){
  Vue.prototype.$baseUrl= 'http://10.168.0.24:9977/api';
}else{
  Vue.prototype.$baseUrl= 'http://'+window.location.hostname+':9977/api';
}

// //切换路由停止接口(切换路由取消接口)
// axios.interceptors.request.use(
//   config => {
//     config.cancelToken = new axios.CancelToken(function (cancel) {
//       store.commit('pushToken', {cancelToken: cancel})
//     })
//     return config
//   }
// )
// //监听路由切换(切换路由取消接口)
// router.beforeEach(function (to, from, next) {
//   store.commit('clearToken') // 取消请求
//   next()
// })
// 时间过滤 毫秒处理   *1000表示按秒处理
Vue.prototype.formatDate = (time, formatStr)=> {
  let date = new Date(time);
  let Y = date.getFullYear();
  let M = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
  let D = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate();
  let h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
  let m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
  let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
  formatStr = formatStr || 'YYYY-MM-DD H:m:s';
  return formatStr.replace(/YYYY|MM|DD|H|m|s/ig, function (matches) {
      return ({
          YYYY: Y,
          MM: M,
          DD: D,
          H: h,
          m: m,
          s: s
      })[matches];
  });
},

/* eslint-disable no-new */
new Vue({
  el: '#app',
  data(){
    return{
      requireAuthNum:1
    }
  },
  router:router,
  store,
  components: { App },
  template: '<App/>',
  created () {
    /* 路由拦截设置 判断当前用户名来进行拦截设置 */ 
      router.beforeEach((to, from, next) => { 
        if (to.matched.some(res => res.meta.requireAuth)) { // 验证是否需要登陆 
        if (localStorage.getItem('_username')) { // 查询本地存储信息是否已经登陆 
          next(); 
        } else { 
        //   this.$notify.info({
        //     title: '请登录后操作',
        //     duration: 1500
        // });
          next({ 
          path: '/', // 未登录则跳转至login页面 
          query: {redirect: to.fullPath} // 登陆成功后回到当前页面，这里传值给login页面，to.fullPath为当前点击的页面 
          }); 
        } 
        } else { 
        next(); 
        } 
      });   
      // const router = new VueRouter({
      //   routes: [
      //   {
      //     path: '/',
      //     component: Index,
      //     props: (route) =>({ query: route.query.q })
      //     }
      //   ]
      //   })
  }
})